{include file="public/layout" /}

<body>
<link rel="stylesheet" href="__SKIN__/css/page.css" media="all">

<div class="layui-fluid" id="LAY-component-layer-list">
    <div class="layui-card">
        <div class="head-oper">
            <div class="fl">
                {notempty name='$gourl'}
                <a href="{$gourl}" class="layui-btn layui-btn-primary  input-btn-back"><i class="layui-icon layui-icon-left"></i></a>
                {/notempty}
                {eq name="'Custom@add'|is_check_access" value="1"}
                <a data-url="{:url('Custom/add', ['channel'=>$Request.param.channel, 'typeid'=>$Request.param.typeid])}" data-type="Custom_add" class="layui-btn mt5 ">新增文档</a>
                {/eq}
            </div>
            <div class="fr">
                <form action="{:url('Custom/index')}" id="searchForm" method="get" onsubmit="layer_loading();">
                    {$searchform.hidden|default=''}
                    <div class="fl mt5" >
                        <div class="layui-input-inline">
                            {gt name='$typeidNum' value='1'}
                            <select name="typeid" id="searchTypeid">
                                <option value="">--所有文档--</option>
                                {$arctype_html}
                            </select>
                            {/gt}
                        </div>
                        <div class="layui-input-inline w240">
                            <input type="hidden" name="channel" value="{$Request.param.channel|default=0}">
                            <input type="text" name="keywords" id="keywords" value="{$Request.param.keywords}" placeholder="标题搜索" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-input-inline w50 mt5">
                        <button class="layui-btn input-btn-search" type="submit"><i class="layui-icon layui-icon-search"></i></button>
                    </div>
                </form>
            </div>
        </div>
        <div class="layui-card-body">
            <div class="layui-form layui-border-box layui-table-view house-table" lay-id="admin-arctype" >
                <div class="layui-table-box">
                    <div class="layui-table-body " >
                        <table cellspacing="0" cellpadding="0" border="0" class="layui-table layui-form" style="width: 100%" lay-skin="line">
                            <thead >
                            <tr>
                                <th class="w40 tc">
                                    <div class="layui-table-cell w40 tc laytable-cell-checkbox">
                                        <input type="checkbox" lay-filter="checkAll" class="checkAll" lay-skin="primary" >
                                        <div class="layui-unselect layui-form-checkbox" lay-skin="primary"> <i class="layui-icon layui-icon-ok"></i></div>
                                    </div>
                                </th>
                                <th class="w100 tc"> <div class="layui-table-cell w100 tc" ><span>ID</span></div></th>
                                <th class="wauto"> <div class="layui-table-cell wauto"><span>标题</span></div></th>
                                <th class="w100 tc"> <div class="layui-table-cell w100 tc"><span>所属栏目</span></div></th>
                                <th class="w80 tc"> <div class="layui-table-cell w80 tc"><span>推荐</span></div></th>
                                <th class="w80 tc"> <div class="layui-table-cell w80 tc"><span>浏览量</span></div></th>
                                <th class="w110 tc"> <div class="layui-table-cell w110 tc"><span>更新时间</span></div></th>
                                <th class="w80 tc"> <div class="layui-table-cell w80 tc"><span>排序</span></div></th>
                                <th class="w220 tc"> <div class="layui-table-cell w220 tc"><span>操作</span></div></th>
                            </tr>
                            </thead>
                            <tbody>
                            {empty name="list"}
                            <tr>
                                <td class="no-data" align="center" axis="col0" colspan="9">
                                    <i class="fa fa-exclamation-circle"></i>没有符合条件的数据
                                </td>
                            </tr>
                            {else /}
                            {foreach name="list" item="vo" key="k" }
                            <tr>
                                <td>
                                    <div class="layui-table-cell w40 tc laytable-cell-checkbox">
                                        <input type="checkbox" name="ids[]" lay-filter="ids" value="{$vo.aid}" lay-skin="primary">
                                    </div>
                                </td>
                                <td><div class="layui-table-cell w100 tc"> {$vo.aid} </div></td>
                                <td>
                                    <div class="layui-table-cell wauto" title=" ">
                                        {eq name="$Think.const.CONTROLLER_NAME.'@edit'|is_check_access" value="1"}
                                        <a href="javascript:void(0);" data-url="{:url('Custom/edit',array('id'=>$vo['aid'], 'channel'=>$Request.param.channel))}" class="eju-event" data-type="Custom_edit" style="{eq name="vo.is_b" value="1"} font-weight: bold;{/eq}">{$vo.title}</a>
                                        {else /}
                                        {$vo.title}
                                        {/eq}
                                        {assign name='showArcFlagData' value='$vo|showArchivesFlagStr'}
                                        {volist name='$showArcFlagData' id="vo1"}
                                            {eq name='$i' value='1'}<span style="color: red;">[{/eq}
                                            <b style="font-size: 12px;">{$vo1['small_name']}</b>
                                            {eq name='$i' value='$showArcFlagData|count'}]</span>{/eq}
                                        {/volist}
                                    </div>
                                </td>
                                <td>
                                    <div class="layui-table-cell w100 tc">
                                        <a href="{:url('Custom/index', array('typeid'=>$vo['typeid'], 'channel'=>$Request.param.channel))}">{$vo.typename|default='<i class="red">数据出错！</i>'}</a>
                                    </div>
                                </td>
                                <td>
                                    <div class="layui-table-cell w80 tc">
                                        <input type="checkbox" name="is_recom"  data-id="{$vo.aid}" value="{$vo.is_recom}" lay-filter="is_recom" lay-skin="switch" lay-text="是|否" {if condition="$vo.is_recom" value="1"} class="yes" checked{else /}class="no"{/if}>
                                    </div>
                                </td>
                                <td>
                                    <div class="layui-table-cell w80 tc">
                                        {$vo.click}
                                    </div>
                                </td>
                                <td><div class="layui-table-cell w110 tc">  {$vo.update_time|date='Y-m-d',###} </div></td>
                                <td>
                                    <div class="layui-table-cell w80 tc">
                                        {eq name="$Think.const.CONTROLLER_NAME.'@edit'|is_check_access" value="1"}
                                        <input type="text" onchange="changeTableVal('archives','aid','{$vo.aid}','sort_order',this);" size="4" value="{$vo.sort_order}" class="layui-input" onkeyup="this.value=this.value.replace(/[^\d]/g,'');" onpaste="this.value=this.value.replace(/[^\d]/g,'');" />
                                        {else /}
                                        {$vo.sort_order}
                                        {/eq}
                                    </div>
                                </td>
                                <td>
                                    <div class="layui-table-cell w220 tc right-oper">
                                        {eq name="$Think.const.CONTROLLER_NAME.'@edit'|is_check_access" value="1"}
                                        <a data-url="{:url('Custom/edit',array('id'=>$vo['aid'], 'channel'=>$Request.param.channel))}" class="layui-btn btn-edit" data-type="Custom_edit">
                                            编辑
                                        </a>
                                        {/eq}
                                        <a href="{$vo.arcurl}" target="_blank" class="layui-btn btn-primary" >
                                            浏览
                                        </a>
                                        {eq name="$Think.const.CONTROLLER_NAME.'@del'|is_check_access" value="1"}
                                        <a class="layui-btn btn-primary" data-url="{:url('Custom/del', ['channel'=>$Request.param.channel])}" data-id="{$vo.aid}" data-type="Custom_del" data-deltype="pseudo" >
                                            删除
                                        </a>
                                        {/eq}
                                    </div>
                                </td>
                            </tr>
                            {/foreach}
                            {/empty}
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="layui-table-page footer-oper">
                    <input type="checkbox" lay-filter="checkAll" class="checkAll" lay-skin="primary" >
                    <div class="nav-dropup">
                        <button class="layui-btn layui-btn-primary dropdown-bt" >批量操作<i class="layui-icon layui-icon-up"></i></button>
                        <div class="dropdown-menu">
                            {eq name="'Archives@batch_copy'|is_check_access" value="1"}
                            <a  href="javascript:;" data-url="{:url('Archives/batch_copy', array('typeid'=>$vo['typeid']))}" onclick="func_batch_copy(this, 'ids');" id="batch_copy">
                                批量复制
                            </a>
                            {/eq}
                            {eq name="'Archives@move'|is_check_access" value="1"}
                            <a  href="javascript:;" onclick="func_move(this,'ids')" id="batch_move_all" data-url="{:url('Archives/move', array('typeid'=>$vo['typeid']))}">
                                批量移动
                            </a>
                            {/eq}
                            {eq name="'Archives@del'|is_check_access" value="1"}
                            <a  href="javascript:;" onclick="batch_del(this,'ids');" id="batch_del_all" data-url="{:url('Archives/del')}" data-deltype="pseudo">
                                批量删除
                            </a>
                            {/eq}
                            <!--<hr class="layui-bg-gray">-->
                            <!--{eq name="'Archives@add_attribute'|is_check_access" value="1"}-->
                            <!--<a  href="javascript:;"  onclick="func_haddle_attribute(this, 'ids','添加');" data-url="{:url('Archives/add_attribute')}" id="add_attribute">-->
                                <!--添加属性-->
                            <!--</a>-->
                            <!--{/eq}-->
                            <!--{eq name="'Archives@del_attribute'|is_check_access" value="1"}-->
                            <!--<a  href="javascript:;" onclick="func_haddle_attribute(this,'ids','删除')" data-url="{:url('Archives/del_attribute')}"  id="del_attribute">-->
                                <!--删除属性-->
                            <!--</a>-->
                            <!--{/eq}-->

                        </div>
                    </div>
                    {eq name="'RecycleBin@archives_index'|is_check_access" value="1"}
                    <a class="layui-btn layui-btn-primary" lay-href="{:url('RecycleBin/archives_index')}" title="回收站"><i class="layui-icon layui-icon-delete"></i>回收站</a>
                    {/eq}
                </div>
                <!--分页-->

            </div>
            {$pageStr}
        </div>
    </div>
</div>

<script>
    var aids = '';
    layui.config({
        base: '__SKIN__/' //静态资源所在路径
        ,version: '{$version}'
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function(){
        var $ = layui.$
            ,form = layui.form
            ,table = layui.table;

        /* 触发事件 */
        var active = {
            Custom_add: function(){
                var iframes = layer.open({
                    type: 2,
                    title: false,
                    closeBtn: false,
                    fixed: true, //不固定
                    shadeClose: false,
                    shade: 0.3,
                    content: $(this).data('url')
                });
                layer.full(iframes);
            }
            ,Custom_edit: function(){
                var iframes = layer.open({
                    type: 2,
                    title: false,
                    closeBtn: false,
                    fixed: true, //不固定
                    shadeClose: false,
                    shade: 0.3,
                    content: $(this).data('url')
                });
                layer.full(iframes);
            }
            ,Custom_del: function(){
                delfun(this);
            }
        };

        $('#LAY-component-layer-list .layui-btn,.eju-event').on('click', function(){
            var type = $(this).data('type');
            active[type] && active[type].call(this);
        });

        $('#searchTypeid').change(function(){
            $('#searchForm').submit();
        });

        //开启关闭
        form.on('switch(is_recom)', function(obj){
            var dataid = $(this).attr('data-id');
            if ($(this).val() == 1){
                $(this).val(0);
            }else{
                $(this).val(1);
            }
            changeTableVal('archives','aid',dataid,'is_recom',this);
        });

        // 监听复选框全选
        form.on('checkbox(checkAll)', function(data){
            if (data.elem.checked) {
                $('.checkAll').attr('checked', true);
                $('input[name*=ids]').attr('checked', true);
            } else {
                $('.checkAll').attr('checked', false);
                $('input[name*=ids]').attr('checked', false);
            }
            form.render('checkbox');
        });

        // 监听每行复选框
        form.on('checkbox(ids)', function(data){
            if (data.elem.checked && $('input[name*=ids]:checked').length == $('input[name*=ids]').length) {
                $('.checkAll').attr('checked', true);
            } else {
                $('.checkAll').attr('checked', false);
            }
            form.render('checkbox');
        });
    });

    $(function () {
        var openurl = "{$Request.param.openurl}";
        var msg = "{$Request.param.msg}";
        if (openurl){
            var iframes = layer.open({
                type: 2,
                title: false,
                closeBtn: false,
                fixed: true, //不固定
                shadeClose: false,
                shade: 0.3,
                content: openurl
            });
            layer.full(iframes);
        }
    });

    function func_move(obj, name)
    {
        var a = [];
        var k = 0;
        aids = '';
        $('input[name^='+name+']').each(function(i,o){
            if($(o).is(':checked')){
                a.push($(o).val());
                if (k > 0) {
                    aids += ',';
                }
                aids += $(o).val();
                k++;
            }
        })
        if(a.length == 0){
            showErrorAlert('请至少选择一项');
            return;
        }

        var url = $(obj).attr('data-url');
        //iframe窗
        layer.open({
            type: 2,
            title: '移动文档',
            fixed: true, //不固定
            shadeClose: false,
            shade: 0.3,
            maxmin: false, //开启最大化最小化按钮
            area: ['450px', '350px'],
            content: url
        });
    }
    //批量处理属性
    function func_haddle_attribute(obj, name,text){
        var a = [];
        var k = 0;
        aids = '';
        $('input[name^='+name+']').each(function(i,o){
            if($(o).is(':checked')){
                a.push($(o).val());
                if (k > 0) {
                    aids += ',';
                }
                aids += $(o).val();
                k++;
            }
        })
        if(a.length == 0){
            showErrorAlert('请至少选择一项');
            return;
        }
        var url = $(obj).attr('data-url');
        //iframe窗
        layer.open({
            type: 2,
            title: '批量'+text+'属性',
            fixed: true, //不固定
            shadeClose: false,
            shade: 0.3,
            maxmin: false, //开启最大化最小化按钮
            area: ['450px', '330px'],
            content: url
        });
    }
    //批量复制
    function func_batch_copy(obj, name)
    {
        var a = [];
        var k = 0;
        aids = '';
        $('input[name^='+name+']').each(function(i,o){
            if($(o).is(':checked')){
                a.push($(o).val());
                if (k > 0) {
                    aids += ',';
                }
                aids += $(o).val();
                k++;
            }
        })
        if(a.length == 0){
            showErrorAlert('请至少选择一项');
            return;
        }

        var url = $(obj).attr('data-url');
        //iframe窗
        layer.open({
            type: 2,
            title: '批量复制',
            fixed: true, //不固定
            shadeClose: false,
            shade: 0.3,
            maxmin: false, //开启最大化最小化按钮
            area: ['450px', '330px'],
            content: url
        });
    }

    /**
     * 获取修改之前的内容
     */
    function get_aids()
    {
        return aids;
    }
    $(".dropdown-bt").click(function(){
        $(".dropdown-menu").slideToggle(200);
        event.stopPropagation();
    })
    $(document).click(function(){
        $(".dropdown-menu").slideUp(200);
        event.stopPropagation();
    })
</script>
{include file="public/footer" /}
